<?php
require "../includes/db.php"; 
$mysqli = new MossCMS();
if ($_SESSION[$prefix.'_username'] == ""){  header("Location: ../login.php"); exit;}
if ($_SESSION[$prefix."_security"] < 1){header("location:../login.php?action=5"); exit;}


$action = $_GET['action'];
$time	= $_GET['updates'];

	if($action == 'delete'){
	$update_id = $_GET['update_id'];
		$mysqli->announce_remove($update_id);
header("location:updates_list.php?action=update_removed"); exit;
}


if ($_SERVER['REQUEST_METHOD'] == "POST") { 


	$content	= $_POST['editor1'];


	$mysqli->announce_add($content,$_SESSION[$prefix.'_username']);

		

		$mysqli->admin_action($z_user, "Added an announcement");
header("location:updates_list.php?action=update_added"); exit;
}//END POST 



$action = $_GET['action'];
$news_id = $_GET['id'];


?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="../includes/admin.css"/>
<title><?php echo $global_title;?></title>


<?php echo $ckeditor_global; ?>
</head>
<body>

<div id="wrap">
	<div id="page-header">
		<?php include('includes/header.php');?>

	</div>
	
	<div id="page-body">
		<div id="tabs">
			<?php $tab="main"; include('includes/header_tabs.php');?>
		</div>

		<div id="acp">
		<div class="panel">
			<span class="corners-top"><span></span></span>
				<div id="content">
				<div id="menu">
						
					<?php include('includes/menu_top.php');?>	
					<?php include('includes/menu_main.php');?>
					</div>
	
					<div id="main">
<a name="maincontent"></a>


<h1>Announcements</h1>
	
<form action="" method="post" enctype="multipart/form-data" name="form1">
    
        <fieldset><legend>Add Anouncement</legend>
		  

			<textarea name="editor1" id="editor1" class="nicedit_textarea" style="height: 300px;"></textarea>
            
            
                       
<p class="submit-buttons"><input type="submit" class="button1" name="submit" id="submit" value="Add Announcement" /></p>

        </fieldset>

    </form>

<h2>Past Announcements</h2>
  <table class="underline">
          <thead>
          <tr>
          	<th>Time</th>
            <th>Message</th>
            <th>User</th>
            <th>Actions</th>
          </tr>
          </thead>
          <tbody>
          <?php
			$results = $mysqli->announce_list();
      			for($x=0; $x < sizeof($results); $x++) {
				if($class == 'row2'){$class = 'row1';}else{$class = 'row2';}

			$date = date('l, F j - g:i:s a',(strtotime($results[$x]['update_timestamp'])));
			$title_link = "<a href='../article.php?id=".$results[$x]['page_id']."'>".$results[$x]['page_name']."</a>";

					
		$edit_link = "<a href ='pages_edit.php?id=".$results[$x]['page_id']."'>Edit</a>";
		$edit_title = "<a href ='pages_edit.php?id=".$results[$x]['page_id']."'>".$results[$x]['page_name']."</a>";
		$delete_link = "<a href =\"javascript:;\" onclick=\"assure(". $results[$x]['content_id'].");\">$icon_delete</a>";
		//echo "<tr class='$class'><td>".$edit_title."</td><td>".$img_link."</td><td>".$date."</td><td>".$edit_link.$delete_link."</td></tr>";
			?>
			<tr class="<?php echo $class;?>">
				<td><?php echo $date;?></td>
				<td><?php echo $results[$x]['update_text'];?></td>
				<td><?php echo $results[$x]['username'];?></td>
				<td><a href='updates_list.php?action=delete&update_id=<?php echo $results[$x]['update_id'];?>'>Delete</a></td>
			</tr>
			<?php } ?>
			            
    	</tbody>
        </table>
<br><br>
    
		</div><!-- main -->
	</div><!-- content -->
<span class="corners-bottom"><span></span></span>
</div><!-- panel -->
</div><!-- acp -->

	
	<div id="page-footer">
	<?php include('includes/footer.php');?>
				</div>
</div><!-- page-body -->
</div><!-- wrap -->

   <script type="text/javascript">
   
	CKEDITOR.replace( 'editor1', {toolbar : 'MyToolbar'} );
	
	CKEDITOR.config.width = '98%';
	CKEDITOR.config.height = '150';
	CKEDITOR.config.resize_maxWidth = '98%';
	CKEDITOR.config.toolbarStartupExpanded = 'true';
	
</script>


</body> 
</html>